package com.kaka.web_maven.dao;

import com.kaka.web_maven.entity.Adimgs;
import com.kaka.web_maven.entity.Users;

import java.sql.*;
import java.util.ArrayList;
import java.util.List;

public class AdimgsDao {
    public List<Adimgs> getList() {
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test_maven",
                    "root","");
            PreparedStatement pstmt = conn.prepareStatement("SELECT * FROM adimgs ORDER BY img_order ASC LIMIT 0,4");
            ResultSet rs = pstmt.executeQuery();
            List<Adimgs> list =new ArrayList<>() ;
            while(rs.next()){
                Adimgs img= new Adimgs();
                img.setId(rs.getInt("id"));
                img.setImg_desc(rs.getString("img_desc"));
                img.setImg_url(rs.getString("img_url"));
                img.setImg_page(rs.getString("img_page"));
                img.setImg_order(rs.getInt("img_order"));
                list.add(img);
            }
            System.out.println(list);
            rs.close();
            conn.close();
            return list;
        }catch (Exception e){
                e.printStackTrace();
        }
        return null;

    }

}
